<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
	<script src="lib/axios.min.js"></script>
</head>
<body>
<button>发送请求</button>
<button>取消请求</button>
</body>
<script>
	const btns = document.querySelectorAll("button");
	let calcelFn = null;
	btns[0].onclick = function () {
		if(calcelFn){
			calcelFn();
		}
		axios.get("http://zhangpeiyue.com/scoreList",{
			cancelToken:new axios.CancelToken(function(cancel){
				// console.log(11111,cancel)
				calcelFn = cancel;
			}),
			// timeout:1000
		}).then(value=>{
			console.log(value.data);
		}).catch(err=>{
			// isCalcel:负责判断异常信息是否为取消发送请求产生的
			console.log(axios.isCancel(err));
			console.log("err",err)
		})
	}
	btns[1].onclick = function () {
		if(calcelFn){
			calcelFn();
		}
	}
</script>
</html>